<?php
	global $user;
	$username = $user->name;

    global $global_ws_address;

	$context = stream_context_create(array(
		'http' => array(
			'timeout' => 10      // Timeout in seconds
		)
	)); 
	
	$url1 = $global_ws_address.'o=getuserinfo&p1='.$username;
	$result1 = @file_get_contents($url1,0,$context);
	$result1 = json_decode($result1, true);

	$url2 = $global_ws_address.'o=allproduct';
	$result2 = @file_get_contents($url2,0,$context);
	$productList = json_decode($result2, true);
?>

<html>
<head>

	<script type="text/javascript" src="jquery.js"></script>
	
	<script type="text/javascript"> 
	    $(document).ready(function(){
			$('#addCVE').click(function(){
				var last = $('#cveList li:last').index();
				last++;
				$('#cveList').append('<li><input type="text" name="cve'+last+'"/></li>');
			});
			$('#delCVE').click(function(){
				$('#cveList li:last').remove();		
			});
			$('#delProduct').click(function(){
				$('#productList li:last').remove();		
			});
		});
		function addProduct(){
				var last = $('#productList li:last').index();
				last++;
				var value = $('#chooseProduct').val();
				$('#productList').append(
					'<li><input type="text" name="product'+last+'" value="'+value+'"/></li>'	
				);
		}
	</script>

	<style type="text/css"> 
		#profile{
			margin:5px;
			padding:5px;
			background:#F5F5DC;
			border:solid 2px #c3c3c3;
		}
	</style>

</head>
 
<body>

	<p>
		Please fill in the following fields.
	</p>

	<div id="profile">
	<?php
		echo '<b>Username: '.$username.'</b><br/><br/>';
	?>
		<form method="post" action="?q=node/18">
			
			Choose your interested products and CVEs for the service to suggest useful information to you in 'MY PAGE'.
			 <fieldset>
				  <legend>Product List</legend>
					Choose a product name in the drop-down list below to add it to your product list. Click 'Del' to delete the latest field.
					<ol id="productList">
						<?php
							if(is_array($result1['product'])){
								$productnum = count($result1['product']);
								for ($i=0; $i<$productnum; $i++){
									echo '<li><input type="text" name="product'.$i.'" value="'.$result1['product'][$i].'"/></li>';
								}
							}else{
									echo 'Add your interested Products';
							}
						?>
					</ol>
					<input type="button" value="Del" id="delProduct"/><br/><br/>
					<select id="chooseProduct">
						<option value="">Products</option>
						<?php
							if( is_array($productList)){
								foreach( $productList as $index => $item ){
									echo '<option value="'.$item['product'].'">'.$item['product'].'</option>';
								}
							}
						?>
					</select>
					<input type="button" value="Add" onClick="addProduct()"/>
			 </fieldset>

			<fieldset>
					<legend>CVE List</legend>
					Fill a CVE name in each entry to add it to you CVE list. Add more or delete entries following your number of CVEs.<br/>
					For example: CVE-2010-3424
					<ol id="cveList">
						<?php
							if(is_array($result1['cve'])){
								$cvenum = count($result1['cve']);
								for ($i=0; $i<$cvenum; $i++){
									echo '<li><input type="text" name="cve'.$i.'" value="'.$result1['cve'][$i].'"/></li>';
								}
							}else{
								echo 'Add your interested CVEs';
							}
						?>
					</ol>
					<input type="button" id="addCVE" value="Add"/>
					<input type="button" id="delCVE" value="Del"/>
			</fieldset>
			 
			 Choose your notification types for the service to notify important events to you.
			  <fieldset>
				  <legend>Notification</legend>
				  <input type="checkbox" name="notiftype" value="email" 
				  <?php echo $result1['notification_email']=='1'? 'checked="checked"':''?>/> via E-MAIL
				  <br/>
				  Your E-mail Address: <input type="text" name="email" 
				  value="<?php echo $result1['notification_email']=='1'? $result1['email']:''?>"/> 
				  <br/>
				  For example: asvrrservice@gmail.com
				  <br/><br/>
				  <input type="checkbox" name="notiftype" disabled="disabled" value="sms" 
				  <?php echo $result1['notification_sms']=='1'? 'checked="checked"':''?>/> via SMS
				  <br/>
				  Your Mobile Phone Number: <input type="text" disabled="disabled" name="sms" 
				  value="<?php echo $result1['notification_sms']=='1'? $result1['tel']:''?>"/> 
				  <br/>
				  For example: 0847890984
				  <br/><br/>
				  <input type="checkbox" name="notiftype" disabled="disabled" value="twitter" 
				  <?php echo $result1['notification_twitter']=='1'? 'checked="checked"':''?>/> via TWITTER
                  <br/>
				  Your Twitter's Account: <input type="text"  disabled="disabled" name="twitter" 
				  value="<?php echo $result1['notification_twitter']=='1'? $result1['twitter']:''?>"/> 
				  <br/>
				  For example: @asvrrs
			 </fieldset>
			
			<br/><br/>
			<input type="reset" name="reset" value="Reset Blank"/>
			<input type="submit" name="submit" value="Submit!"/>
		</form>
	</div>

</body>
</html>